# -*- codeing = utf-8 -*-
# @Time : 2024/3/21 17:24
# @Author : huangjing
# @File : my_database.py
# @Software : PyCharm
import pymysql

# 建立数据库连接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='password',
    database='mydatabase'
)

# 创建游标对象
cursor = conn.cursor()

# 执行查询
cursor.execute("SELECT * FROM mytable")

# 获取查询结果
result = cursor.fetchall()
for row in result:
    print(row)

# 关闭游标和连接
cursor.close()
conn.close()